<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model :model="model" :form="form" :rules="rules" ref="form" layout="vertical">
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="日期" prop="time">
<!--              <a-input placeholder="请输入" v-model="model.time" style="width: 100%" />-->
              <a-date-picker v-model:value="time" placeholder="选择日期" style="width:100%" :allowClear="false"
                             @change="changeTime"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="车间" prop="workshop">
              <j-dict-select-tag placeholder="请选择车间" v-model="model.workshop" dictCode="workshop"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="班次" prop="classes">
              <j-dict-select-tag placeholder="请选择班次" v-model="model.classes" dictCode="shift"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="上班时间" prop="workHours">
              <a-input-number placeholder="请输入" v-model="model.workHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="机台时间" prop="machineHours">
              <a-input-number placeholder="请输入" v-model="model.machineHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机台" prop="machine">
              <a-input placeholder="请输入" v-model="model.deviceNo" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="工号" prop="workNoBlockingCar">
              <a-input placeholder="请输入" v-model="model.workNo" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="姓名" prop="nameBlockingCar">
              <a-input placeholder="请输入" v-model="model.realname" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
<!--        <a-row class="form-row" :gutter="16">-->
<!--          <a-col :span="6">-->
<!--            <a-form-model-item label="工号-落纱" prop="workNoDoff">-->
<!--              <a-input placeholder="请输入" v-model="model.workNoDoff" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="6">-->
<!--            <a-form-model-item label="姓名-落纱" prop="nameDoff">-->
<!--              <a-input placeholder="请输入" v-model="model.nameDoff" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="6">-->
<!--            <a-form-model-item label="工号-摆管" prop="workNoSwingPipe">-->
<!--              <a-input placeholder="请输入" v-model="model.workNoSwingPipe" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="6">-->
<!--            <a-form-model-item label="姓名-摆管" prop="nameSwingPipe">-->
<!--              <a-input placeholder="请输入" v-model="model.nameSwingPipe" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--        </a-row>-->
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="品种类别" prop="productCategory">
              <a-input placeholder="请输入" v-model="model.productCategory" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="品种" prop="productType">
              <j-dict-select-tag placeholder="请选择品种" v-model="model.productType" style="width: 100%" dictCode="crm_product_type_spun_yarn,product_type,id" @change="changeProductType"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="支数" prop="productBranch">
              <a-input placeholder="请输入" v-model="model.productBranch" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="挡车机台系数" prop="blockingCarMachineCoefficient">
              <a-input placeholder="请输入" v-model="model.blockingCarMachineCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="挡车品种系数" prop="blockingCarProductTypeCoefficient">
              <a-input placeholder="请输入" v-model="model.blockingCarProductTypeCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="挡车单价系数" prop="blockingCarUnitPriceCoefficient">
              <a-input placeholder="请输入" v-model="model.blockingCarUnitPriceCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="挡车综合系数" prop="blockingCarComprehensiveCoefficient">
              <a-input placeholder="请输入" v-model="model.blockingCarComprehensiveCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱机台系数" prop="doffMachineCoefficient">
              <a-input placeholder="请输入" v-model="model.doffMachineCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="落纱品种系数" prop="doffProductTypeCoefficient">
              <a-input placeholder="请输入" v-model="model.doffProductTypeCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱单价系数" prop="doffUnitPriceCoefficient">
              <a-input placeholder="请输入" v-model="model.doffUnitPriceCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="挡车综合系数" prop="doffComprehensiveCoefficient">
              <a-input placeholder="请输入" v-model="model.doffComprehensiveCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="锭数" prop="ingotsNum">
              <a-input placeholder="请输入" v-model="model.ingotsNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="定量" prop="quantify">
              <a-input placeholder="请输入" v-model="model.quantify" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="8小时定额长度" prop="fixedLengthEightHours">
              <a-input placeholder="请输入" v-model="model.fixedLengthEightHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="台数" prop="machinesNum">
              <a-input placeholder="请输入" v-model="model.machinesNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="台数(8小时)" prop="machinesNumEightHours">
              <a-input placeholder="请输入" v-model="model.machinesNumEightHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="挡车定额看台（台）" prop="blockingCarFixedMachinesNum">
              <a-input placeholder="请输入" v-model="model.blockingCarFixedMachinesNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱定额看台（台）" prop="doffFixedMachinesNum">
              <a-input placeholder="请输入" v-model="model.doffFixedMachinesNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="挡车总看台率（%）" prop="blockingCarTotalMachinesRate">
              <a-input placeholder="请输入" v-model="model.blockingCarTotalMachinesRate" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱总看台率（%）" prop="doffTotalMachinesRate">
              <a-input placeholder="请输入" v-model="model.doffTotalMachinesRate" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="落纱队别" prop="doffTeam">
              <a-input placeholder="请输入" v-model="model.doffTeam" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱队人数" prop="doffTeamNum">
              <a-input placeholder="请输入" v-model="model.doffTeamNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱个人数" prop="doffPeopleNum">
              <a-input placeholder="请输入" v-model="model.doffPeopleNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱数（次/台）" prop="doffNum">
              <a-input placeholder="请输入" v-model="model.doffNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="台位换纱锭数" prop="machinesChangeYarnIngotsNum">
              <a-input placeholder="请输入" v-model="model.machinesChangeYarnIngotsNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="挡车工换纱锭数（锭/台）" prop="blockingCarChangeYarnIngotsNum">
              <a-input placeholder="请输入" v-model="model.blockingCarChangeYarnIngotsNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱工换纱锭数（锭/台）" prop="doffChangeYarnIngotsNum">
              <a-input placeholder="请输入" v-model="model.doffChangeYarnIngotsNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="接班长度" prop="takeoverLength">
              <a-input placeholder="请输入" v-model="model.takeoverLength" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="交班长度" prop="handoverLength">
              <a-input placeholder="请输入" v-model="model.handoverLength" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="实际长度" prop="realityLength">
              <a-input placeholder="请输入" v-model="model.realityLength" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="重量（kg）" prop="weight">
              <a-input placeholder="请输入" v-model="model.weight" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="挡车单价（百米/元）" prop="blockingCarUnitPrice">
              <a-input placeholder="请输入" v-model="model.blockingCarUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="落纱单价（百米/元）" prop="doffUnitPrice">
              <a-input placeholder="请输入" v-model="model.doffUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="换纱单价（元/落）" prop="changeYarnUnitPrice">
              <a-input placeholder="请输入" v-model="model.changeYarnUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱清洁单价（元/台）" prop="doffCleanUnitPrice">
              <a-input placeholder="请输入" v-model="model.doffCleanUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱产量单价（元/台）" prop="doffProductionUnitPrice">
              <a-input placeholder="请输入" v-model="model.doffProductionUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="摆管单价（元/台）" prop="swingPipeUnitPrice">
              <a-input placeholder="请输入" v-model="model.swingPipeUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="挡车工资（元）" prop="blockingCarWages">
              <a-input placeholder="请输入" v-model="model.blockingCarWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="挡车换纱工资（元）" prop="blockingCarChangeYarnWages">
              <a-input placeholder="请输入" v-model="model.blockingCarChangeYarnWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="挡车系数补扣" prop="blockingCarCoefficientDeduction">
              <a-input placeholder="请输入" v-model="model.blockingCarCoefficientDeduction" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="挡车其他补贴" prop="blockingCarOtherSubsidies">
              <a-input placeholder="请输入" v-model="model.blockingCarOtherSubsidies" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="挡车合计工资" prop="blockingCarTotalWages">
              <a-input placeholder="请输入" v-model="model.blockingCarTotalWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱台产量工资（元）" prop="doffMachinesProductionWages">
              <a-input placeholder="请输入" v-model="model.doffMachinesProductionWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱次数工资（元）" prop="doffFrequencyWages">
              <a-input placeholder="请输入" v-model="model.doffFrequencyWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="落纱台系数补扣" prop="doffMachinesCoefficientDeduction">
              <a-input placeholder="请输入" v-model="model.doffMachinesCoefficientDeduction" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱次数个人工资（元）" prop="doffFrequencyPersonalWages">
              <a-input placeholder="请输入" v-model="model.doffFrequencyPersonalWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="换纱工资（元）" prop="changeYarnWages">
              <a-input placeholder="请输入" v-model="model.changeYarnWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱清洁工资（元）" prop="doffCleanWages">
              <a-input placeholder="请输入" v-model="model.doffCleanWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="落纱个人产量工资（元）" prop="doffPersonalProductionWages">
              <a-input placeholder="请输入" v-model="model.doffPersonalProductionWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱队长补贴（元）" prop="doffTeamLeaderSubsidies">
              <a-input placeholder="请输入" v-model="model.doffTeamLeaderSubsidies" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱系数补扣" prop="doffCoefficientDeduction">
              <a-input placeholder="请输入" v-model="model.doffCoefficientDeduction" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="落纱其他补贴" prop="doffOtherSubsidies">
              <a-input placeholder="请输入" v-model="model.doffOtherSubsidies" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="落纱合计工资" prop="doffTotalWages">
              <a-input placeholder="请输入" v-model="model.doffTotalWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="摆管工资（元）" prop="swingPipeWages">
              <a-input placeholder="请输入" v-model="model.swingPipeWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="完成率" prop="completionRate">
              <a-input placeholder="请输入" v-model="model.completionRate" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机台保养" prop="machinesMaintenance">
              <a-input placeholder="请输入" v-model="model.machinesMaintenance" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="备注" prop="remark">
              <a-input placeholder="请输入" v-model="model.remark" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import JEditor from '@/components/jeecg/JEditor'
import JSwitch from '@/components/jeecg/JSwitch'

import moment from 'moment'
import { getShiftSystem, productTypeSpunYarn } from '../../../../api/customApi'
export default {
  name: 'DeviceModal',
  components: {
    JEditor,
    JSwitch,
  },
  data() {
    return {
      title: '操作',
      visible: false,
      time: null,
      workHours: null,
      machineHours: null,
      disable: true,
      model: {
        productCategory:'',
        productBranch:'',
        blockingCarMachineCoefficient:'',
        blockingCarProductTypeCoefficient:'',
        blockingCarUnitPriceCoefficient:'',
        blockingCarComprehensiveCoefficient:'',
        doffMachineCoefficient:'',
        doffProductTypeCoefficient :'',
        doffUnitPriceCoefficient:'',
        doffComprehensiveCoefficient:'',
        ingots:'',
        quantify:'',
        fixedLengthEightHours:'',
        blockingCarFixedMachinesNum:'',
        doffFixedMachinesNum:'',
        weight:'',
        blockingCarUnitPrice:'',
        changeYarnUnitPrice:'',
        doffCleanUnitPrice:'',
        doffProductionUnitPrice:'',
        swingPipeUnitPrice:'',
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      url: {
        add: '/crm_salary_excel_spun_yarn/crmSalaryExcelSpunYarn/add',
        edit: '/crm_salary_excel_spun_yarn/crmSalaryExcelSpunYarn/edit',
      },
    }
  },
  created() {},
  methods: {
    changeWorkHours(date, dateString){
      this.model.workHours = dateString + " 00:00:00"
      // this.model.workHours = new Date(dateString).getTime()
    },
    changeMachineHours(date, dateString){
      this.model.machineHours = dateString + " 00:00:00"
      // this.model.machineHours = new Date(dateString).getTime()
    },
    changeProductType(val){
      productTypeSpunYarn({ id:val }).then((res) => {
        // this.model = res.result.records[0]
        this.model.productCategory = res.result.records[0].productCategory
        this.model.productBranch = res.result.records[0].productBranch
        this.model.blockingCarMachineCoefficient = res.result.records[0].blockingCarMachineCoefficient
        this.model.blockingCarProductTypeCoefficient = res.result.records[0].blockingCarProductTypeCoefficient
        this.model.blockingCarUnitPriceCoefficient = res.result.records[0].blockingCarUnitPriceCoefficient
        this.model.blockingCarComprehensiveCoefficient = res.result.records[0].blockingCarComprehensiveCoefficient
        this.model.doffMachineCoefficient = res.result.records[0].doffMachineCoefficient
        this.model.doffProductTypeCoefficient = res.result.records[0].doffProductTypeCoefficient
        this.model.doffUnitPriceCoefficient = res.result.records[0].doffUnitPriceCoefficient
        this.model.doffComprehensiveCoefficient = res.result.records[0].doffComprehensiveCoefficient
        this.model.ingots = res.result.records[0].ingots
        this.model.quantify = res.result.records[0].quantify
        this.model.fixedLengthEightHours = res.result.records[0].fixedLengthEightHours
        this.model.blockingCarFixedMachinesNum = res.result.records[0].blockingCarFixedMachinesNum
        this.model.doffFixedMachinesNum = res.result.records[0].doffFixedMachinesNum
        this.model.weight = res.result.records[0].weight
        this.model.blockingCarUnitPrice = res.result.records[0].blockingCarUnitPrice
        this.model.changeYarnUnitPrice = res.result.records[0].changeYarnUnitPrice
        this.model.doffCleanUnitPrice = res.result.records[0].doffCleanUnitPrice
        this.model.doffProductionUnitPrice = res.result.records[0].doffProductionUnitPrice
        this.model.swingPipeUnitPrice = res.result.records[0].swingPipeUnitPrice
      })
    },
    changeTime(date, dateString){
      this.model.planTime = dateString
    },
    add() {
      this.disable = false
      this.edit({}, 1)
    },
    edit(record, isEdit) {
      if (isEdit != 1) {
        this.model = Object.assign({}, record)
        this.time = moment(this.model.planTime)
      }

      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.disable = true
      this.$refs.form.resetFields();
    },

    handleOk() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let formData = Object.assign(this.model)
          console.log('formData', formData)
          //时间格式化
          httpAction(httpurl, formData, method)
            .then((res) => {
              if (res.success) {
                this.$message.success(res.message)
                this.$emit('ok')
              } else {
                this.$message.warning(res.message)
              }
            })
            .finally(() => {
              this.confirmLoading = false
              this.close()
            })
        } else {
          return false
        }
      })
    },

    handleCancel() {
      this.close()
    },
  },
}
</script>

<style scoped>

</style>